export default class PropertiesPanelConfig {

    // 模块名称
    #modelName;
    // 配置
    #config;

    constructor(modelName,propConfig) {
        if(!modelName){
            throw Error("modelName 不能为空")
        }
        if(!propConfig){
            throw Error("请导入 @/components/Workflow/CustomPropertiesPanel/config/ 下对应文件夹的properties.js文件信息")
        }
        this.#config = propConfig;
        this.#modelName = modelName;
    }

    /**
     * 根据类型获取对应的属性配置
     * @param elementType
     * @returns {{}|*}
     */
    getConfigByElementType(elementType){
        let strings = Object.keys(this.#config);
        let elementProperties = strings.filter(d=> d === elementType);
        if(elementProperties && elementProperties.length > 0 ){
            return this.#config[elementProperties[0]];
        }
        return null;
    }

    /**
     * 将配置文件中的properties属性转换为数组,便于面板渲染
     * @param prop
     * @returns {*[]}
     */
    propertiesToArray(prop){
        let strings = Object.keys(prop);
        let result = [];
        strings.forEach(key=>{
            let obj = {};
            obj.name = key;
            obj.prop = prop[key];
            result.push(obj);
        })
        return result;
    }

    /**
     * 将bpmn节点转换成属性对象
     * @param element
     * @returns {*}
     */
    elementToProperties(element){

        return element;
    }

}
